function [O sim_mom] = imo_2011_NLS_all3FE(beta,data,prm,output)

% Fixed parameters
K = data.K;             % Number of destination         


lnt_n = beta(prm.idx_t_n);
lnt_p = [beta(prm.idx_t_p) 0];
phisig1_p = beta(prm.idx_phisig1_p);
a_n = beta(prm.idx_a_n);
a_p = [beta(prm.idx_a_p) 1];

lntmat = repmat(lnt_n',1,data.P) + repmat(lnt_p,data.K,1);
a = repmat(a_n',1,data.P).*repmat(a_p,data.K,1);

eta = [];
for n=1:data.K
    for p=1:data.P
      if data.usedata(n,p)==1
                
        lnXhat = a(n,p) + phisig1_p(p)*log(data.price{n,p} + exp(lntmat(n,p)));         
        resid = data.lnX{n,p} - lnXhat;
        eta = [eta; resid];        
      end
    end
end
O = sum(eta.^2);
end